package com.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DBCreator {
	private static String driver = "org.apache.derby.jdbc.EmbeddedDriver";
	private static String dbName = "jdbcDemoDB";
	private static String connectionURL = "jdbc:derby:" + dbName
			+ ";create=true";
	private static Connection conn = null;
	Statement s;
	PreparedStatement psInsert;
	ResultSet myWishes;
	String printLine = "  __________________________________________________";
	public static String createString = "CREATE TABLE WISH_LIST  "
			+ "(WISH_ID INT NOT NULL GENERATED ALWAYS AS IDENTITY "
			+ "   CONSTRAINT WISH_PK PRIMARY KEY, "
			+ " ENTRY_DATE TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "
			+ " WISH_ITEM VARCHAR(32) NOT NULL) ";
	
	public static String createReconciledTradeTableString ="create table reconciledtrades(id BIGINT generated always as identity, sellTradeId bigint, buytradeid bigint, buyQty int)";
	
	public static String createTradeTableString = "create table trades"+
	"(tradeid BIGINT generated always as identity, Date TIMESTAMP,"+
	"Stock VARCHAR(32),"+
	"Action VARCHAR(5),"+
	"\"Qty.\" INT,"+
	"\"Price#\" DOUBLE,"+
	"\"Trade Value\" DOUBLE,"+
	"\"Brokerage incl. taxes\" DOUBLE,"+
	"\"Order Ref.\" VARCHAR(32),"+
	"Settlement VARCHAR(32),"+
	"Segment VARCHAR(32),"+
	"\"DP Id - Client DP Id\" VARCHAR(32),"+
	"Exchange VARCHAR(32)"+
	")";
	String answer;

	public static Connection getConnection() {
		System.out.println("going to load driver");
		synchronized (DBCreator.class) {
			
				try {
					if (conn == null||conn.isClosed()) {				
							Class.forName(driver).newInstance();
							System.out.println(driver + " loaded. ");
							conn = DriverManager.getConnection(connectionURL);				
					}
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (InstantiationException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IllegalAccessException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (ClassNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			
			return conn;
		}
	}
}
